package com.bysj.money_diary;

import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class LeibieAdapter extends BaseAdapter {

	private ArrayList<String> leibiearr;
	private Context context;
	private int flag = 0;
	private	String subItem="";

	public LeibieAdapter(Context context, int flag,String subitem) {
		this.flag = flag;
		this.context = context;
		//
		if(flag==Jiyibi.zhichu_flag){
			getLeibieList(Item.leibie_s);
		}else if(flag==Jiyibi.shouru_flag){
			getLeibieList(Item.shoru_s);
		}else if(flag==Jiyibi.jiedai_flag){
			getLeibieList(Item.jiedai_s);
		}else if(flag==Leibie.flagsubleibie){
			getLeibieSubList(subitem);
		}
	}

	/*
	 * 
	 * */
	public void getLeibieList(String s[]) {
		leibiearr = new ArrayList<String>();
		for (String str : s) {
			leibiearr.add(str);
		}
	}

	/*
	 * 
	 * */
	public void getLeibieSubList(String subitem) {
		leibiearr = new ArrayList<String>();
		String strs[]=null;
		if(subitem.equals("餐饮")){
			strs=Item.cy_s;
		}else if(subitem.equals("交通")){
			strs=Item.jt_s;
		}else if(subitem.equals("购物")){
			strs=Item.gw_s;
		}else if(subitem.equals("娱乐")){
			strs=Item.yl_s;
		}else if(subitem.equals("居家")){
			strs=Item.jj_s;
		}else if(subitem.equals("投资")){
			strs=Item.tz_s;
		}else if(subitem.equals("人情")){
			strs=Item.rq_s;
		}
		this.subItem = subitem;
		for (String str : strs) {
			leibiearr.add(str);
		}
	}

	public int getCount() {
		return leibiearr.size();
	}

	public Object getItem(int position) {
		return leibiearr.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	private RelativeLayout addsub=null;
	@SuppressLint("InflateParams")
	public View getView(int position, View convertView, ViewGroup parent) {
		if (flag!=Leibie.flagsubleibie) {
			convertView = LayoutInflater.from(context).inflate(R.layout.jiyibi_leibie_item, null);
			String lb = leibiearr.get(position);
			TextView lb_text = (TextView) convertView.findViewById(R.id.leibie_item_text);
			addsub = (RelativeLayout) convertView.findViewById(R.id.jz_item_addsub_rl);
			convertView.setTag(lb);
			//
			addsub.setTag(lb);
			lb_text.setText(lb);
		} else {
			convertView = LayoutInflater.from(context).inflate(R.layout.jiyibi_leibie_subitem, null);
			TextView sublb_text = (TextView) convertView.findViewById(R.id.leibie_subitem_text);
			String lb = leibiearr.get(position);
			convertView.setTag(subItem+">"+lb);
			sublb_text.setText(lb);
		}
		return convertView;
	}
}
